
#include "EnergyTimeDerivativeADKernelSUPG.h"

registerMooseObject("TrilobitaApp", EnergyTimeDerivativeADKernelSUPG);

InputParameters
EnergyTimeDerivativeADKernelSUPG::validParams()
{
    InputParameters params = ADTimeKernelGrad::validParams();
    params.addClassDescription(
        "SUPG stablization terms for the time derivative of the pyrolysis energy equation.");
    params.addRequiredCoupledVar("velocity", "Velocity vector variable.");
    return params;
}

EnergyTimeDerivativeADKernelSUPG::EnergyTimeDerivativeADKernelSUPG(const InputParameters& parameters)
    : ADTimeKernelGrad(parameters), 
    _velocity(adCoupledVectorValue("velocity")),
    _energy_td_strong_residual_factor(getADMaterialProperty<Real>("energy_td_strong_residual_factor"))
{
}

ADRealVectorValue
EnergyTimeDerivativeADKernelSUPG::precomputeQpResidual()
{
    ADReal tau =
        _current_elem->hmin() /
        (2 * (_velocity[_qp] + RealVectorValue(libMesh::TOLERANCE * libMesh::TOLERANCE)).norm());
    return tau * _velocity[_qp] * _energy_td_strong_residual_factor[_qp] * _u_dot[_qp];
}
